/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package co.edu.uniminuto.arqSw.ejercicio.DAO;

import co.edu.uniminuto.arqSw.ejercicio.Hibernate.HibernateUtil;
import co.edu.uniminuto.arqSw.ejercicio.Hibernate.Persona;
import java.util.ArrayList;
import java.util.List;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;

/**
 *
 * @author diegoalejandro
 */
public class PersonaDao {
    
    private Session sesion=null;

    public PersonaDao() {
        this.sesion= HibernateUtil.getSessionFactory().getCurrentSession();
    }
    
    public List<Persona> getPersonas(){
        List<Persona> personas= new ArrayList<Persona>();
        
        try {
           Transaction tx= this.sesion.beginTransaction();
           Query query= this.sesion.createQuery("From Persona p order by p.idPersona asc");
           personas= (List<Persona>) query.list();
        } catch (Exception e) {
            e.printStackTrace();
        }
        
        return personas;
    }
    
       public List<Persona> getViviendas(){
        List<Persona> personas= new ArrayList<Persona>();
        
        try {
           Transaction tx= this.sesion.beginTransaction();
           Query query= this.sesion.createQuery("From Vivienda v order by v.codVivienda asc");
           personas= (List<Persona>) query.list();
        } catch (Exception e) {
            e.printStackTrace();
        }
        
        return personas;
    }
       
          public List<Persona> getTelefonos(){
        List<Persona> personas= new ArrayList<Persona>();
        
        try {
           Transaction tx= this.sesion.beginTransaction();
           Query query= this.sesion.createQuery("From Telefono t order by t.idTelefono asc");
           personas= (List<Persona>) query.list();
        } catch (Exception e) {
            e.printStackTrace();
        }
        
        return personas;
    }
    
}
